"""
__author__ = '霍格沃兹测试开发学社'
__desc__ = '更多测试开发技术探讨，请访问：https://ceshiren.com/t/topic/15860'
"""
from dao import result_formatter_dao
from orm_domain.result_formatter import ResultFormatter

# todo: Lixu 参数实体类
class ResultFormatterService:
    """
    """

    def save(self, execution_id, job_id, data):
        """
        生成测试报告
        post接口需要返回新增的数据信息
        """
        result_formatter = ResultFormatter(execution_id=execution_id, job_id=job_id, data=data)
        result_formatter_dao.save(result_formatter)

    def get_by_execution(self, execution_id):
        """
        execution_id: 执行器id
        """
        r_obj = result_formatter_dao.get(execution_id=execution_id)
        return r_obj

    def get_by_job_id(self, job_id):
        """
        execution_id: job id
        """
        r_obj = result_formatter_dao.get_list(job_id=job_id)
        return r_obj

    def get_by_sub_job_id(self, sub_job_id):
        """
        execution_id: 子job id
        """
        r_obj = result_formatter_dao.get(sub_job_id=sub_job_id)
        return r_obj

    def delete_by_sub_job_id(self, sub_job_id):
        """
        execution_id: 子job id
        """
        r_obj = result_formatter_dao.get(sub_job_id=sub_job_id)
        if not r_obj:
            return False
        result_formatter_dao.delete(r_obj)
        return True

    def delete_by_job_id(self, job_id):
        """
        job_id: job id
        """
        r_obj = result_formatter_dao.get_list(job_id=job_id)
        if not r_obj:
            return False
        for obj in r_obj:
            result_formatter_dao.delete(obj)
        return True
